package com.diandi.signature.manager.impl.signaturepkg;

import com.diandi.signature.bean.pkgmsg.SignatureBusinessPkgmsg;
import com.diandi.signature.manager.signaturepkg.SignaturePkgMsgManager;
import com.diandi.signature.mapper.SignatureBusinessPkgmsgMapper;
import com.diandi.signature.mapper.SignaturePkgMsgMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by mxp on 2017/8/31.
 */
@Component
public class SignaturePkgMsgManagerImpl implements SignaturePkgMsgManager {
    private Logger logger = LoggerFactory.getLogger(SignaturePkgMsgManagerImpl.class);

    @Autowired
    private SignaturePkgMsgMapper signaturePkgMsgMapper;

    @Autowired
    private SignatureBusinessPkgmsgMapper signatureBusinessPkgmsgMapper;

    @Override
    public Integer savePkgMsg(String userId, String tradeNo, String passCode, String merchantNo, String interfactType, String requestMsg, int status,String pkgmsgType) {
        Map<String, Object> pkgMap = new HashMap<String, Object>();
        pkgMap.put("userId", userId);
        pkgMap.put("tradeNo", tradeNo);
        pkgMap.put("passCode", passCode);
        pkgMap.put("merchantNo", merchantNo);
        pkgMap.put("interfaceType", interfactType);
        pkgMap.put("requestMsg", requestMsg);
        pkgMap.put("status", status);
        pkgMap.put("pkgmsgType", pkgmsgType);
        Integer savePkgMsg = signaturePkgMsgMapper.savePkgMsg(pkgMap);
        if (savePkgMsg == null || savePkgMsg == 0){
            logger.warn("save signaturePkgMsg failed, msg is [{}]", pkgMap.toString());
        }
        return savePkgMsg;
    }

    @Override
    public Integer updatePkgMsg(String returnMsg, String tradeNo, String userId, String passCode, int status) {
        Map<String, Object> pkgMap = new HashMap<String, Object>();
        pkgMap.put("returnMsg", returnMsg);
        pkgMap.put("status", status);
        pkgMap.put("tradeNo", tradeNo);
        pkgMap.put("userId", userId);
        pkgMap.put("passCode", passCode);

        Integer updatePkgMsg = signaturePkgMsgMapper.updatePkgMsg(pkgMap);

        if (updatePkgMsg == null || updatePkgMsg == 0){
            logger.warn("update signaturePkgMsg failed, msg is [{}]", pkgMap.toString());
        }
        return updatePkgMsg;
    }

    @Override
    public SignatureBusinessPkgmsg getSignaturePkgMsg(Map<String, String> paramMap) {
        return signatureBusinessPkgmsgMapper.getSignatureBusinessPkgmsgByTrade(paramMap);
    }
}
